Skip to content

fix buffer overrun and write failure in forward iterator range_adapter - #195

Open
aouxwoux wants to merge 1 commit into
boostorg:developfrom
aouxwoux:fix-range-adapter-forward-iterators
Open

aouxwoux wants to merge 1 commit into
boostorg:developfrom
aouxwoux:fix-range-adapter-forward-iterators

Conversation

@aouxwoux

@aouxwoux aouxwoux commented Oct 25, 2026 •

Copy link
Copy Markdown

fixes #191

what changed

  • in
    ange_adapter_implstd::forward_iterator_tag::read, count consumed elements explicitly instead of post-decrementing
    em. when characters remained in the range, the post-decrement in while (cur != last && rem-- > 0) evaluated when
    em == 0, decrementing
    em to -1 and returning
  • rem = n + 1, which overran the destination buffer and corrupted stream reading across buffer boundaries.
  • in
    ange_adapter_implstd::forward_iterator_tag::write, count written elements instead of decrementing
    , ensuring write returns the number of characters written (
    ) and correctly throws write_area_exhausted() when count < n.
  • add unit tests in est/forward_range_test.hpp covering reading forward ranges exceeding buffer size, matching buffer size, smaller than buffer size, empty ranges, multi-buffer direct reading, buffered writes exceeding buffer size, writing with excess, exact, and insufficient capacity, and forward iterators returning proxy reference types.
  • all test additions are c++03 compatible without c++11 features.
  • extend
    ead_input_seq_test.hpp and write_output_seq_test.hpp with std::list forward iterator sequence test cases.

checks

fix post-decrement off-by-one in range_adapter_impl<forward_iterator_tag>::read which returned n + 1 when characters remained in the range, causing stream buffer corruption. fix write which mutated n and returned -1 or 0 instead of characters written. add tests covering forward iterator ranges.

fixes boostorg#191
@aouxwoux
aouxwoux force-pushed the fix-range-adapter-forward-iterators branch from 94f988a to ada43c0 Compare October 25, 2026 17:17
@aouxwoux aouxwoux closed this Nov 24, 2026
@aouxwoux aouxwoux reopened this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stream corruption when reading from forward-iterator range exceeding stream buffer size

1 participant